<template>
  <div class="groups-show">
    <div v-if="false">{{myDate}}</div>
    <div class="headline">
      <span></span>组合秀
      <a href="javascript:" class="more" @click.stop.prevent = "toGreatGroup">查看更多&gt</a>
    </div>
    <table class="table">
      <tbody>
      <tr v-for="item in groupList" @click.stop.prevent="toGroupDetail(item)">
        <td class="one">
          <div class="wrapper-xs">
            <div class="key">总收益率</div>
            <div class="value" :class='item.totalProfit.indexOf("-") >= 0 ? "negative": "positive"'> {{item.totalProfit}} </div>
          </div>
        </td>

        <td class="two">
          <div class="">组合</div>
          <div class="">
            <div class="group-name text-left">{{item.groupName}}</div>
            <div class="creator text-left">
              <span class="nickname">{{item.nickname}}</span>
              <span>创建</span>
            </div>
          </div>
        </td>

        <td class="three">
          <div class="">{{item.stealers}}</div>
          <div class="">人偷师</div>
        </td>

        <td class="four">
          <i class="iconfont icon-xiangyou"></i>
        </td>
      </tr>
      <div class="no-data" v-if="groupList.length == 0">{{error || '暂无数据'}}</div>
      </tbody>
    </table>
  </div>
</template>

<script>
  import _ from "underscore"
  import RemoteDAO from 'common/remoteDAO'
  import CommonUtil from 'common/common.util'

  export default {
    data () {
      return {
        title: '牛人牛股',
        groupList: [],
        error: '数据加载中...',
        myDate:'myDate'
      }
    },
    created: function () {
      this.fetchData()
    },
    methods: {
      fetchData () {
        // 组合秀查询
        RemoteDAO.callJCL30016(response=>{
          if (Number(response.error) === 0) {
            let list = []
            let data = response.data.body.data
            if (data.length > 0 ) {
              data = _.sortBy(data, "total_profit").reverse() // 对数字排序，非字符串
            }
            _.each(data, function(item, index) {
              let object = {}
              object.totalProfit = CommonUtil.toFixed(item.total_profit, 2) + "%"
              object.nickname = item.nickname
              object.clientId = item.client_id
              object.groupName = item.group_name
              object.groupId = item.group_id
              object.stealers = item.stealers
              list.push(object)
            })
            this.groupList = list
            this.error = ''
          }else{
            this.error = response.data
          }
        })
      },
      /**
       * 跳转组合详情页
       * @param item
       */
      toGroupDetail (item) {
        this.$router.push({ path: '/groupdetail', query: { clientId:item.clientId, groupId: item.groupId}});
        var kv = {"usercode": "","k2":""};
        TDAPP.onEvent("14008","",kv);
        TDAPP.send();
      },
      toGreatGroup(){//组合秀查看更多
        this.$router.replace({path:'/greatstock/bestgroupbox/0'});
        var kv = {"usercode": "","k2":""};
        TDAPP.onEvent("14008","",kv);
        TDAPP.send();
      }
    }
  }
</script>

<style scoped>

</style>
